package com.ephra.dao.servlet.user;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ephra.commons.JsonUtils;
import com.ephra.dao.factory.Factory;
import com.ephra.dao.model.User;
import com.google.gson.Gson;
import com.sun.org.apache.xalan.internal.xsltc.compiler.sym;

public class Login extends HttpServlet{

	/**
	 *
	 */
	private static final long serialVersionUID = -9045601282295538952L;

	public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException {
		response.setContentType("text/json;charset=UTF-8");
	    response.setCharacterEncoding("UTF-8");
	    PrintWriter out=response.getWriter();
		String username=request.getParameter("username").toString();
		String password=request.getParameter("password").toString();
		
		String str ="{\"data\":\"ERROR\"}";
		try {

			if(Factory.getUser().login(username, password).getUsername().equals(username)){
				str ="{\"data\":\"SUCCESS\"}";
			}
			out.println(str);
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {
		this.doGet(request, response);
	}
}

